#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <cmath>
#include <cstring>
#include <string>
#include <iomanip>
#include <climits>
#include <unordered_map>
#include <unordered_set>
#define int long long
#define x first 
#define y second  
using namespace std;
const int N = 2e6 + 10;

void solve()
{
    string s;
    cin >> s;
    int ans = 0;
    int ans1 = 0;
    for(int i = 1; i < s.size(); i++)
    {
          if(s[i] == 'L' && s[i] == s[i - 1]) ans++;
          if(s[i] == 'Q' && s[i] == s[i - 1]) ans1++;
    }
    cout << s.size() - max(ans,ans1) << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int t = 1;
    while(t -- )  solve();
    return 0;
}